#define _CRT_SECURE_NO_WARNINGS   1

#include<iostream>
#include<vector>
#include<stack>

#define N 5
using namespace std;

class Solution {
public:
	bool IsPopOrder(vector<int> pushV, vector<int> popV)
	{
		int n = 0;
		int j = 0;
		for (int num : pushV)
		{
			pushV[n] = num;
			while (n >= 0 && pushV[n] == popV[j])
			{
				j++;
				n--;
			}
			n++;
		}
		return n == 0;
	}
};

int main()
{
	Solution Sol;
	vector<int>pushV;
	vector<int>popV;
	int num;
	for (int i = 0; i < N; i++)
	{
		cin >> num;
		pushV.push_back(num);
	}
	for (int i = 0; i < N; i++)
	{
		cin >> num;
		popV.push_back(num);
	}
	if (Sol.IsPopOrder(pushV, popV))
		cout << "True" << endl;
	else
		cout << "False" << endl;
	return 0;
}